﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using 温湿度和颗粒度监控测试.Common;
using 温湿度和颗粒度监控测试.ViewModel;

namespace 温湿度和颗粒度监控测试.View
{
    /// <summary>
    /// 综合显示Window.xaml 的交互逻辑
    /// </summary>
    public partial class 综合显示Window : Window
    {
        public 综合显示Window()
        {
            InitializeComponent();

            DataContext = new 综合显示WindowViewModel()
            {
                InfoMessageEvent = msg => MessageBoxHelper.Info(msg),
                ErrorMessageEvent = msg => MessageBoxHelper.Error(msg),
                ConfirmMessageEvent = msg => MessageBoxHelper.Confirm(msg) == MessageBoxResult.Yes,
                停止监控Event = () => 停止监控Event?.Invoke(),
            };
        }

        public delegate void 窗口事件Handler();
        public 窗口事件Handler 窗口关闭Event;
        public 窗口事件Handler 停止监控Event;

        public void 开始监控()
        {
            try
            {
                综合显示WindowViewModel vm = DataContext as 综合显示WindowViewModel;
                vm.开始监控();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }

        public void 停止监控()
        {
            try
            {
                综合显示WindowViewModel vm = DataContext as 综合显示WindowViewModel;
                vm.停止监控();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageBoxHelper.Error(ex.Message);
            }
        }
    }
}
